package com.four.bmm.controller;

import com.four.bmm.entity.News;
import com.four.bmm.service.NewsService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 展示新闻详情Servlet,
 */
@WebServlet("/ShowNewsInfoServlet")
public class ShowNewsInfoServlet extends HttpServlet {


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int newsId = Integer.parseInt(req.getParameter("id"));
        NewsService newsService = new NewsService();
        newsService.addSeeCount(newsId);
        News news = newsService.getNewsById(newsId);
                    /*newsService.addSeeCount(1);
                   News news=newsService.getNewsById(1);*/
        req.setAttribute("news", news);
        req.getRequestDispatcher("single.jsp").forward(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
